/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightAdjustFood;
import com.sasis.dao.FlightAdjustFoodDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightAdjustFoodDaoiBatis extends BaseDaoiBATIS implements FlightAdjustFoodDao {

    /**
     * @see com.sasis.dao.FlightAdjustFoodDao#getFlightAdjustFoods(com.sasis.model.FlightAdjustFood)
     */
    public List getFlightAdjustFoods(final FlightAdjustFood flightAdjustFood) {
          return getSqlMapClientTemplate().queryForList("getFlightAdjustFoods", flightAdjustFood);
    }

    /**
     * @see com.sasis.dao.FlightAdjustFoodDao#getFlightAdjustFood(Integer id)
     */
    public FlightAdjustFood getFlightAdjustFood(Integer id) {
        FlightAdjustFood flightAdjustFood = (FlightAdjustFood) getSqlMapClientTemplate().queryForObject("getFlightAdjustFood", id);

        //if (flightAdjustFood == null) {
            //throw new ObjectRetrievalFailureException(FlightAdjustFood.class, id);
        //}

        return flightAdjustFood;
    }

    /**
     * @see com.sasis.dao.FlightAdjustFoodDao#saveFlightAdjustFood(FlightAdjustFood flightAdjustFood)
     */    
    public int saveFlightAdjustFood(final FlightAdjustFood flightAdjustFood) {
        Integer id = flightAdjustFood.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightAdjustFood", flightAdjustFood);
        } else {
            getSqlMapClientTemplate().update("updateFlightAdjustFood", flightAdjustFood);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightAdjustFood.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightAdjustFoodDao#removeFlightAdjustFood(Integer id)
     */
    public void removeFlightAdjustFood(FlightAdjustFood flightAdjustFood) {
        getSqlMapClientTemplate().update("deleteFlightAdjustFood",  flightAdjustFood);
    }
    
    public void deleteFlightAdjustFood(FlightAdjustFood flightAdjustFood){
    	getSqlMapClientTemplate().update("deleteFoodByFlightInfoId",  flightAdjustFood);
    }
}
